package org.dh2580.delay.queue.bean.model;

/**
 * 延迟消息对象
 *
 * @Author: hao.deng
 * @Date: 2019/5/14-下午7:23
 */
public class DelayMsg {

    /**
     * 消息ID
     */
    private Long id;

    /**
     * 路由Key
     */
    private String routeKey;

    /**
     * 消息
     */
    private String msg;

    /**
     * TTL
     */
    private Long ttl;

    /**
     * 确认状态
     */
    private AckState ackState;

    /**
     * 创建时间
     */
    private Long createTime;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getRouteKey() {
        return routeKey;
    }

    public void setRouteKey(String routeKey) {
        this.routeKey = routeKey;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Long getTtl() {
        return ttl;
    }

    public void setTtl(Long ttl) {
        this.ttl = ttl;
    }

    public AckState getAckState() {
        return ackState;
    }

    public void setAckState(AckState ackState) {
        this.ackState = ackState;
    }

    public Long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }

    /**
     * ACK确认状态
     */
    public enum AckState implements EnumConvert<Integer, AckState> {
        /**
         * 初始状态
         */
        INIT(0),

        /**
         * 已分发状态
         */
        DISTRIBUTED(1),

        /**
         * 已确认状态
         */
        CONFIRMED(2),

        /**
         * 长期未消费抛弃
         */
        ABANDONED(3),
        ;
        private int val;

        AckState(int val) {
            this.val = val;
        }


        @Override
        public AckState convertToEnum(Integer integer) {
            switch (val) {
                case 0:
                    return INIT;
                case 1:
                    return DISTRIBUTED;
                case 2:
                    return CONFIRMED;
                case 3:
                    return ABANDONED;
                default:
                    return null;
            }
        }
    }

}
